define(["jquery"],function($){
	function Register(){
        this.createDom().addListener();
	}
	Register.modelTemp = `<!-- 注册模态框 -->
	<div class="modal fade" id="ModalRegister" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<h2 class="modal-title" id="myModalLabel">用户注册</h2>
				</div>
				<div class="modal-body">
					<div class="alert alert-success hidden regist-succ text-center" role="alert">注册成功！请登录~</div>
					<div class="modal-body">
						<form class="regist-form">
							<div class="form-group">
								<label for="recipient-name" class="control-label">用户名:</label>
								<input type="text" name="username" class="form-control" id="recipient-name" placeholder="2-10位，可包含汉字、数字、字母、下划线">
							</div>
							<div class="form-group">
								<label for="message-text" class="control-label">密码:</label>
								<input type="password" name="password" class="form-control" placeholder="请输入6-10位的数字加字母的组合密码"></input>
							</div>
							<div class="form-group">
								<label for="message-text" class="control-label">确认密码:</label>
								<input type="password" class="form-control" placeholder="请确认密码"></textarea>
							</div>
							<div class="form-group">
								<label for="message-text" class="control-label">邮箱:</label>
								<input type="email" name="email" class="form-control" placeholder="请输入邮箱"></textarea>
							</div>
						</form>
					</div>
				</div>
				<div class="modal-footer">
				    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary btn-register">注册</button>
				</div>
			</div>
		</div>
	</div>`
	$.extend(Register.prototype,{
		createDom(){
			$(Register.modelTemp).appendTo("body")
			return this;
		},
		addListener(){
			$(".btn-register").on("click",this.registHandle)
			return this;
		},
		registHandle(){
			//const url = "http://rap2api.taobao.org/app/mock/119565/regist",rap2请求
			const url = "/api/users/register",
				  data = $(".regist-form").serialize();
			$.post(url,data,res=>{
				$(".regist-succ").removeClass("hidden");
				setTimeout(()=>{
					$("#ModalRegister").modal('hide');
					$(".log").css("background","orange")
				},2500)
				const username = res.res_body.data.username,
				      password = res.res_body.data.password;
				sessionStorage.username = username;
				sessionStorage.password = password;

			})
		},
		test(){

		}
	})
	return new Register();
})